from tkinter.font import Font
import pandas as pd 
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
pic_font = FontProperties(fname=r"/System/Library/Fonts/PingFang.ttc", size=12) 
import numpy as np
f1 = pd.DataFrame(pd.read_excel('books.xlsx'))
print(f1[f1["作者"] == "金庸"])
print(f1['体裁'].value_counts().head(3))
print(f1.groupby("类别").借阅次数.agg('sum').sort_values())
ans = [0 for i in range(0, 5000)]
for i in range(0, 25):
    ans[f1["出版年份"][i]] = ans[f1["出版年份"][i]] + f1["借阅次数"][i]
X = []
Y = []
for i in range(1947, 2020):
    if ans[i] != 0:
        X.append(i)
        Y.append(ans[i])
print(X)
print(Y)
plt.bar(X, Y, color = 'r')
plt.title("不同出版年份的书籍的总借阅次数", FontProperties = pic_font)
plt.xlabel('出版年份', FontProperties = pic_font)
plt.ylabel('借阅次数', FontProperties = pic_font)
plt.show()
